Skip to content

Use one table by one tag #8

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed

Use one table by one tag #8

wants to merge 1 commit into from

Conversation

babeuloula
Copy link

No description provided.

@cebe
Copy link

cebe commented Jul 2, 2015

can you explain why you made this change?

@babeuloula
Copy link
Author

Sorry, because I have created a jQuery Plugin to merge and for select some change it was more simply.

(function($) {
    $.fn.phpdiff = function(options) {
        var selector = $(this);

        var o = {
            join: true,
            glue: '\n',
            merge_btn: null,
            merge: $.noop(),
            error: $.noop()
        };

        options = $.extend(o, options);

        if(options.merge_btn === null) {
            options.merge_btn = '#merge-btn';
            var btn = $("<button/>").attr('id', 'merge-btn').attr('type', 'button').html('Fusionner').prop('disabled', true);
            btn.insertAfter(selector);
        } else {
            $(options.merge_btn).prop('disabled', true);
        }




        selector.find('.ChangeInsert td, .ChangeDelete td, .ChangeReplace td').addClass('notUsed').click(function(e) {
            e.preventDefault();
            e.stopPropagation();

            var left = $(this).hasClass('Left');

            if(left) {
                $(this).parents('tbody').find('.Left').addClass('use').removeClass('notUsed dontUse');
                $(this).parents('tbody').find('.Right').addClass('dontUse').removeClass('notUsed use');
            } else {
                $(this).parents('tbody').find('.Right').addClass('use').removeClass('notUsed dontUse');
                $(this).parents('tbody').find('.Left').addClass('dontUse').removeClass('notUsed use');
            }

            if(selector.find('.notUsed').length === 0) {
                $(options.merge_btn).prop('disabled', false);
            }
        });



        $(document).on('click', options.merge_btn, function(e) {
            e.preventDefault();
            e.stopPropagation();

            if(selector.find('.notUsed').length > 0) {
                options.error("Il reste encore des zones non séléctionnées.");
            } else {
                var result = [];

                selector.find('tbody').each(function() {
                    switch($(this).attr('class')) {
                        case 'ChangeEqual':
                            result.push($(this).find('.Left').text());
                            break;

                        case 'ChangeInsert':
                        case 'ChangeDelete':
                        case 'ChangeReplace':
                            result.push($(this).find('.use').text());
                            break;
                    }
                });

                if(options.join) {
                    options.merge(result.join(options.glue));
                } else {
                    options.merge(result);
                }
            }
        });


    };
})(jQuery);

@everzet everzet closed this Apr 7, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants